<?php

namespace App\Console\Commands;

use App\Models\MallOrder;
use App\Services\MallOrderService;
use Illuminate\Console\Command;

class TakeDeliver extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'take_deliver';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '自动收货';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        try {
            $date = date("Y-m-d H:i:s");
            MallOrder::where('express_end_at', '<', $date)->where('status', MallOrder::STATUS_DELIVER_PRODUCT)->chunk(50, function ($list) {
                foreach ($list as $key => $val) {
                    $input = [
                        'order_id' => $val->id
                    ];
                    MallOrderService::handle($input, 'receive', true, true);
                }
            });
        }catch (\Exception $e) {

        }

    }
}
